/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.v1.jitclouds.mda.providers;

import br.ufba.lasid.v1.jitclouds.mda.MDA;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.BasicConfiguration;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.virtualization.BasicVirtualMachine;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.virtualization.IVirtualMachine;
import java.util.List;
import java.util.Properties;

/**
 *
 * @author aliriosa
 */
public class VMProvider implements IProvider<IVirtualMachine>{

    @Override
    public IVirtualMachine create(Properties options) throws Exception {
        return prepare(new BasicVirtualMachine(), options, "");                
    }
    
    protected IVirtualMachine prepare(IVirtualMachine machine, Properties options, String prefix){
        String idVM = MDA.BaseOptions.getProperty(MDA.VMTag);
        String dsVM = MDA.Configuration.getString(idVM + ".description");
                
        machine.setID(idVM);
        machine.setDescription(dsVM);
        
        List actions = MDA.Configuration.getList(prefix + ".action");
        
        BasicConfiguration config = new BasicConfiguration();
        
        if(actions != null && !actions.isEmpty()){
            for(Object action : actions){
                String command = MDA.Configuration.getString(prefix + "." + action);
                config.set(action.toString(), command);
            }            
        }
        
        machine.setConfiguration(config);        
        
        return machine;
    }
    
}
